package com.demo.camel08.callmethod;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
import org.apache.log4j.PropertyConfigurator;

public class CallMethodDemo {

    public static void main(String[] args) throws Exception {

        // 日志
        PropertyConfigurator.configure("src/conf/log4j.properties");
        PropertyConfigurator.configureAndWatch("src/conf/log4j.properties", 1000);

        MyService myService = new MyService();
        SimpleRegistry simpleRegistry = new SimpleRegistry();
        simpleRegistry.put("myService", myService);

        CamelContext context = new DefaultCamelContext(simpleRegistry);
        context.start();


        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start").to("bean:myService?method=myMethod");
            }
        });


        ProducerTemplate producerTemplate = context.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "hello camel");

        // 通用没有具体业务意义的代码，只是为了保证主线程不退出
        synchronized (CallMethodDemo.class) {
            CallMethodDemo.class.wait();
        }
    }
}
